﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Cataloger
{
    public partial class FrmDodajTyp : Form
    {
        public FrmDodajTyp()
        {
            InitializeComponent();
        }
        public FrmDodajTyp(TypPliku typ):this()
        {
            this.Text = typ.Nazwa;
            this.textBox1.Text = typ.Nazwa;
            foreach (string s in typ.SlowaW)
            {
                this.listBox1.Items.Add(s);
            }
        }
        private bool czyJestSlowoNaLiscie(string slowo)
        {
            return listBox1.Items.Contains(slowo);
        }
        private void btnDodaj_Click(object sender, EventArgs e)
        {
            if (!czyJestSlowoNaLiscie(txtSlowo.Text.ToLower().Trim()))
            {
                listBox1.Items.Add(txtSlowo.Text.ToLower().Trim());
            }
        }
        public string Nazwa
        {
            get
            {
                return this.textBox1.Text;
            }
        }
        public List<string> Slowa
        {
            get
            {
                List<String> temp = new List<string>();
                foreach (string s in listBox1.Items)
                {
                    temp.Add(s);
                }
                return temp;
            }
        }
        private bool czyPolaWypelnione()
        {
            if (textBox1.Text == "" || listBox1.Items.Count < 1)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
        private void button3_Click(object sender, EventArgs e)
        {
            if (czyPolaWypelnione())
            {
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else
            {
                MessageBox.Show("Błąd danych", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            listBox1.Items.Remove(listBox1.SelectedItem);
        }
    }
}
